package com.rimi.commons;

import lombok.Data;

/**
 * @author liHaiYang
 * @version V1.0
 * @Description: (用一句话描述该文件做什么)
 * @date 2021/6/7 15:32
 */
@Data
public class CommonResult<T> {

    private int code;

    private String message;

    private T data;

    public CommonResult(ResultCode resultCode, T data) {
        this.code = resultCode.getCode();
        this.message=resultCode.getMsg();
        this.data = data;
    }

    /**
     * 成功的消息返回值
     * @param data 成功的返回结果
     * @return
     */
    public  static <T> CommonResult<T> onSuccess(T data){
       return new CommonResult<>(ResultStatus.OK,data);

    }


    /**
     * 失败的回调
     * @param resultCode 失败的原因
     * @return
     */
    public  static <T> CommonResult<T> onFailed(ResultCode resultCode){
        return new CommonResult<>(resultCode,null);
    }

    /**
     * 传code以及数据
     * @param resultCode
     * @param data
     * @param <T>
     * @return
     */
    public  static <T> CommonResult<T> judge(ResultCode resultCode,T data){
        return new CommonResult<>(resultCode,data);
    }

}
